import Vue from 'vue'
import VueRouter from 'vue-router'

// import Reg from '@/views/Reg/Reg.vue'
// import Login from '@/views/Login/Login.vue'
// import Main from '@/views/Main/Main.vue'
// import Home from '@/views/Menus/Home/Home.vue'
// import UserInfo from '@/views/Menus/User/UserInfo.vue'
// import UserAvatar from '@/views/Menus/User/UserAvatar.vue'
// import userPwd from '@/views/Menus/User/userPwd.vue'
// import ArtCate from '@/views/Menus/Article/ArtCate.vue'
// import ArtList from '@/views/Menus/Article/ArtList.vue'

Vue.use(VueRouter)

const routes = [
  {   //注册路由配置
    path:'/reg',
    name:'reg',
    component:() => import('@/views/Reg/Reg.vue')
  },
  {   //登录路由配置
    path:'/Login',
    name:'login',
    component:() => import('@/views/Login/Login.vue')
  },
  {   //首页路由配置
    path:'/',
    name:'main',
    component:() => import('@/views/Main/Main.vue'),
    redirect:'/home',
    children:[
      { //耳机路由嵌套使用,二级路由path不用加斜杆
        path:'home',
        name:'home',
        component:() => import('@/views/Menus/Home/Home.vue'),
      },
      { //基本资料
        path:'user-info',
        name:'userinfo',
        component:() => import('@/views/Menus/User/UserInfo.vue'),
      },
      { //修改用户图像
        path:'user-avatar',
        name:'useravatar',
        component:() => import('@/views/Menus/User/UserAvatar.vue'),
      },
      { //修改用户密码
        path:'user-pwd',
        name:'userpwd',
        component:() => import('@/views/Menus/User/userPwd.vue'),
      },
      { //文章分类
        path:'art-cate',
        name:'artcate',
        component:() => import('@/views/Menus/Article/ArtCate.vue'),
      },
      { //文章列表
        path:'art-list',
        name:'artlist',
        component:() => import('@/views/Menus/Article/ArtList.vue'),
      },
    ]
  },
]

const router = new VueRouter({
  routes
})
// VueRouter.prototype.push: push函数要求不能重复 跳转路由
// 解决办法，就是改写  VueRouter中的push函数，但需要保留之前的功能
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default router
